﻿using System;
using System.Collections.Generic;
using System.Reflection;
using Windows.ApplicationModel.Resources.Core;

namespace BasicLight.Entry
{
    public class Languages
    {
        public static ResourceMap _resourceMap = null;
        public static ResourceContext _resourceContext = null;

        private static void Set(string code)
        {
            if (String.IsNullOrEmpty(code)) code = "zh-CN";

            if (null != _resourceContext)
            {
                _resourceContext = null;
                _resourceMap = null;
            }

            _resourceContext = new ResourceContext();
            _resourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("BasicLight.Entry/" + code);
        }

        /// <summary>
        /// 区域代码
        /// </summary>
        public static string Subtag
        {
            set
            {
                Set(value);
            }
        }

        public static string Get(string name)
        {
            if (null == _resourceContext)
            {
                Set(null);
            }

            return _resourceMap.GetValue(name, _resourceContext).ValueAsString;
        }

        #region 属性

        public static string AppName { get { return Languages.Get("AppName"); } }

        #endregion
    }
}
